//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - lower
//===================================================================================


namespace App.Data.SqlServer.Repositories {
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using App.Model;

    public class SkillRepository : BaseRepository, ISkillRepository {
        public SkillRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork) {
        }
        public void Create(Skill skill) {
            this.GetDbSet<Skill>().Add(skill);
            this.UnitOfWork.SaveChanges();
        }

        public Skill GetSkill(Guid skillId) {
            return this.GetDbSet<Skill>()
                .Where(c => c.Id == skillId)
                .Single();
        }

        public void Update(Skill updatedSkill) {
            this.GetDbSet<Skill>().Attach(updatedSkill);
            this.SetEntityState(updatedSkill, updatedSkill.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid skillId) {
            Skill SkillToDelete = this.GetSkill(skillId);
            this.GetDbSet<Skill>().Remove(SkillToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IQueryable<Skill> Find()
        {
            return this.GetDbSet<Skill>();
        }

        public IQueryable<Skill> GetAll()
        {
            return this.GetDbSet<Skill>();
        }
    }
}
